package com.aiyige.page.selectinterest.adapter;

import android.graphics.Typeface;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.selectinterest.model.InterestItem;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/10/25.
 */

public class InterestAdapter extends BaseQuickAdapter<InterestItem, InterestAdapter.InterestViewHolder> {

    public InterestAdapter() {
        super(R.layout.interest_item, new LinkedList<InterestItem>());
    }

    @Override
    protected void convert(InterestViewHolder helper, InterestItem item) {
        helper.bindData(item);
    }

    public static class InterestViewHolder extends BaseViewHolder {
        @BindView(R.id.titleTv)
        TextView titleTv;
        @BindView(R.id.icon)
        ImageView icon;

        public InterestViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(InterestItem item) {
            if (item.isAllSelected()) {
                titleTv.setText(R.string.all);
                titleTv.setTypeface(null, Typeface.BOLD);
            } else {
                titleTv.setTypeface(null, Typeface.NORMAL);
                titleTv.setText(item.getTitle());
            }
            icon.setVisibility(item.isSelected() ? View.VISIBLE : View.INVISIBLE);
        }
    }

}
